package org.yang.plugins.resource.serializer;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import lombok.SneakyThrows;
import org.yang.plugins.resource.exception.Auth2Exception;

/**
 * TODO 添加Auth2Exception的序列化实现
 *
 * @author: lslands
 * @version: v2.0
 * @create: 2021/6/14 21:56
 **/
public class Auth2ExceptionSerializer extends StdSerializer<Auth2Exception> {

    public Auth2ExceptionSerializer() {
        super(Auth2Exception.class);
    }

    @Override
    @SneakyThrows
    public void serialize(Auth2Exception value, JsonGenerator gen, SerializerProvider provider) {
        gen.writeStartObject();
        gen.writeObjectField("code", 400);
        gen.writeStringField("msg", value.getMessage());
        gen.writeStringField("data", value.getErrorCode());
        gen.writeEndObject();
    }
}
